package sync;

public class SyncDemo {
    private void test() {
        synchronized (this) {
            System.out.println("test");
        }
    }

    public static void main(String[] args) throws InterruptedException {
        SyncDemo demo = null;
        int n = 0;
        for(;;) {
            if(demo == null)
                demo = new SyncDemo();
            demo.test();
            if((n ++ & 0b11) == 0)
                demo = null;
            System.out.println(n);
            Thread.sleep(1000);
        }
    }
}
